﻿using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;

namespace KPIS.GERP.GHRMS.APP.App_UI.UserControls
{
    public partial class PS_HisPrivateInfo : System.Web.UI.UserControl
    {
        private IEmployeeBLL empBLL = new EmployeeBLL();
        private IAddressBLL addBLL = new AddressBLL();

        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected bool IsUserControlPostBack
        {
            get
            {
                return this.ViewState["IsUserControlPostBack"] != null;
            }
        }
        protected override void OnLoad(System.EventArgs e)
        {
            base.OnLoad(e);

            if (!IsUserControlPostBack)
            {
                this.ViewState.Add("IsUserControlPostBack", true);

                if (Request.QueryString["sta"] != null)
                    this.lblSta.Text = Request.QueryString["sta"].ToString();

                lblEmpSeq.Text = Session["emp_seq"].ToString();
                LoadEmployee();
            }
        }
        protected void LoadEmployee()
        {
            DataSet ds = null;
            DataTable dt = null;

            ds = empBLL.LoadEmployees(Convert.ToInt32(lblEmpSeq.Text), "", true, "");
            dt = ds.Tables[0].Copy();
            if (dt.Rows.Count > 0)
            {
                lblOfficialID.Text = dt.Rows[0]["OFFICIAL"].ToString();
                lblEmpTypeName.Text = dt.Rows[0]["EMP_TYPE_NAME"].ToString();
                lblEmpName.Text = dt.Rows[0]["FULL_NAME"].ToString();
                lblEmpNameEng.Text = dt.Rows[0]["FULL_NAME_ENG"].ToString();
                lblPosRef.Text = dt.Rows[0]["POS_REF"].ToString();
                lblPosName.Text = dt.Rows[0]["POS_NAME"].ToString();
                lblClassName.Text = dt.Rows[0]["CLASS_NAME"].ToString();
                lblJobsiteName.Text = dt.Rows[0]["JOB_SITE_NAME"].ToString();
                lblWorkingJobsiteName.Text = dt.Rows[0]["WORKING_JOB_SITE_NAME"].ToString();
                lblSalary.Text = string.Format("{0:N2}", dt.Rows[0]["SALARY"]);
                lblEmpStatusName.Text = dt.Rows[0]["EMP_STATUS_NAME"].ToString();
                lblPositionDate.Text = string.Format("{0:dd/MM/yyyy}", dt.Rows[0]["DATE_LATEST_POS"]);
                lblAdmittedDate.Text = string.Format("{0:dd/MM/yyyy}", dt.Rows[0]["DATE_ADMITTED"]);
                lblRetireDate.Text = string.Format("{0:dd/MM/yyyy}", dt.Rows[0]["RETIRE_DATE"]); //dt.Rows[0]["RETIRE_DATE"].ToString();
                lblBirthDate.Text = string.Format("{0:dd/MM/yyyy}", dt.Rows[0]["BIRTH_DATE"]);
                lblBloodGroup.Text = dt.Rows[0]["BLOOD_GROUP_NAME"].ToString();
                lblCitizen.Text = dt.Rows[0]["CITIZEN"].ToString();
                LoadAddress();

                string strCitizen = dt.Rows[0]["CITIZEN"].ToString();

                if (File.Exists(Server.MapPath("../../OtherImages/Person/" + strCitizen + ".jpg").Replace("\\", "/")))
                    imgEmp.ImageUrl = "../../OtherImages/Person/" + strCitizen + ".jpg";
                else
                    imgEmp.ImageUrl = "~/App_UI/Images/Buttons/No Picture.jpg";
            }
        }
        protected void LoadAddress()
        {
            DataSet ds = null;
            DataTable dt = null;

            ds = addBLL.LoadEmployeeAddress(Convert.ToInt32(lblEmpSeq.Text), (int?)null);
            if (ds.Tables.Count > 0)
            {
                dt = ds.Tables[0].Copy();
                if (dt.Rows.Count > 0)
                {
                    lblAddress1.Text = dt.Rows[0]["ADDRESS_NAME"].ToString();
                    lblTel1.Text = dt.Rows[0]["TEL"].ToString();
                    lblEmail1.Text = dt.Rows[0]["EMAIL"].ToString();
                    if (dt.Rows.Count > 1)
                    {
                        lblAddress2.Text = dt.Rows[1]["ADDRESS_NAME"].ToString();
                        lblTel2.Text = dt.Rows[1]["TEL"].ToString();
                    }
                }
            }
        }
    }
}